package com.ruoyi.web.core.config;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;
 
import java.sql.Connection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
 
@Intercepts({
    @Signature(
        type = StatementHandler.class,
        method = "prepare",
        args = {Connection.class, Integer.class}
    )
})
public class SqlStatementInterceptor implements Interceptor {
 
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
        String sql = statementHandler.getBoundSql().getSql();
        List parms = statementHandler.getBoundSql().getParameterMappings();
        Object obj1 = statementHandler.getParameterHandler().getParameterObject();
        System.out.println("执行的SQL：" + sql);
        System.out.println("参数:"+parms.toString());
        // 继续执行后续操作
        return invocation.proceed();
    }
 
    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }
 
    @Override
    public void setProperties(Properties properties) {
        // 可以接收配置的属性
    }
}